package ecnu.liwaTest.dd;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.HashMap;
import java.util.Map;

public class DriverSingleton {
    private static WebDriver driver;
    static Map<String, Object> vars;
    static JavascriptExecutor js;

    private DriverSingleton() {

    }

    public static WebDriver getChromeDriver() {
        if(driver == null) {
            System.setProperty("webdriver.chrome.driver", "D:\\Program Files (x86)\\selenium driver\\chromedriver.exe");
            driver = new ChromeDriver();
        }
        return driver;
    }

    public static Map<String, Object> getVars() {
        if(vars == null) {
            vars = new HashMap<>();
        }
        return vars;
    }

    public static JavascriptExecutor getJs() {
        return (JavascriptExecutor) driver;
    }

//    @AfterEach
//    public void tearDown() {
//        driver.quit();
//    }

    public static void waitForWindow(int timeout) {
        try {
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
